package com.haojiang.mh.remote.widget

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView
import com.haojiang.mh.R

class RmText: AppCompatTextView {

    var pressType: String? = null
    var code: String? = null
    var img: String? = null

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        //        //使用系统工具获取属性
        val typedArray = context.obtainStyledAttributes(attrs, R.styleable.RmText)
        for (i in 0 until typedArray.indexCount) {
            val index = typedArray.getIndex(i)
            when (index) {
                R.styleable.RmText_pressType -> pressType = typedArray.getString(index)
                R.styleable.RmText_code -> code = typedArray.getString(index)
                R.styleable.RmText_img -> img = typedArray.getString(index)
            }
        }
        //记得回收
        typedArray.recycle()
    }
}